package com.best.oasis.settlement.web.action.base;

import java.util.List;

import javax.annotation.PostConstruct;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.best.oasis.settlement.common.entity.base.BaseEntity;
import com.best.oasis.settlement.service.base.BaseService;
import com.best.oasis.settlement.util.convert.ConvertUtil;
import com.best.oasis.settlement.util.page.BasePageSO;
import com.best.oasis.settlement.util.page.PageList;

public abstract class BaseActionImpl<VO, T extends BaseEntity> implements BaseAction<VO, T> {
	public final String SUCCESS = "success";
	public final String ERROR = "error";
	
	/**
     * Logger for this class
     */
    protected final Log logger = LogFactory.getLog(getClass());

    protected BaseService<T, VO, Long> baseService;
    
    /**
     * 请在这里给baseDao，modelClass和modelVOClass赋值
     * eg.
     *      UserServiceImpl.java:
     *              @PostConstruct
     *              public void afterConstruct(){
     *                  super.setBaseDao(userDao);
     *                  super.setModelClass(user.class);
     *                  super.setModelVOClass(userVO.class);
     *              }
     */
    @PostConstruct
    public void afterConstruct(){
        
    }
    
    public BaseService<T, VO, Long> getBaseService() {
		return baseService;
	}
	public void setBaseService(BaseService<T, VO, Long> baseService) {
		this.baseService = baseService;
	}

    public VO get(Long id) {
    	return baseService.get(id);
    }
    
    public VO create(VO vo) {
        return baseService.create(vo);
    }
    
    public VO update(VO vo) {
    	return baseService.update(vo);
    }
    
    public void remove(Long id) {
        baseService.remove(id);
    }
    
    public void remove(List<Long> ids) {
        baseService.remove(ConvertUtil.toLongs(ids));
    }
    
    public boolean exists(Long id) {
        return baseService.exists(id);
    }
    
    public PageList<VO> getPageList(BasePageSO so) {
    	if(so == null){
    		so = new BasePageSO();
    	}
        return baseService.getPageList(so);
    }
    public List<VO> getAll() {
        return baseService.getAll();
    }
    public List<VO> getAll(BasePageSO so){
        return baseService.getAll(so);
    }
    
    public VO getBy(String fieldName, Object value) {
        return baseService.getBy(fieldName, value);
    }

    public List<VO> getByIds(List<Long> ids) {
        return baseService.getByIds(ids);
    }
    
    public List<VO> getListBy(String fieldName, Object value) {
        return baseService.getListBy(fieldName, value);
    }


}
